package http.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author fengbo
 * @date 2018/10/19
 */
public class SocketHttpServer {

    private static final ExecutorService pools = Executors.newFixedThreadPool(10);
//    private static final ScheduledExecutorService scheduled = Executors.newSingleThreadScheduledExecutor();

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8088);
//        scheduled.scheduleWithFixedDelay(HttpTask.CACHE::clear, 1, 1, TimeUnit.HOURS);
        for (;;) {
            Socket conn = serverSocket.accept();
            // 单线程
//            new HttpTask(request, response).run();
            // 每次请求启动一个线程
//            new Thread(new HttpTask(conn)).start();
            // 使用线程池
            pools.submit(new HttpTask(conn));
        }
    }
}
